Skip to content

Fix arithmetic that overflows a 32-bit Int - #80

Merged
colemancda merged 7 commits into
masterfrom
fix/32-bit-overflow
Dec 3, 2026
Merged

colemancda merged 7 commits into
masterfrom
fix/32-bit-overflow

Conversation

@colemancda

Copy link
Copy Markdown
Member

On 32-bit targets such as PowerPC Linux, some intermediate values pass what an Int holds. These are now computed in Int64.

File On 32-bit before
ColorModels.swift Trapped converting bright colors
PointAngle.swift Wrong angles for larger rectangles
Pattern.swift Trapped in blend mode with bright colors
Mapping.swift Trapped mapping points between large rectangles
CopyBits.swift Trapped scaling between very large rectangles
Picture.swift Could overflow scaling a picture to a very large size (found by reading)

The first two were found running the QuickDraw capture probes natively on an iBook G4; the rest by reading the code.

Testing

  • macOS: swift test passes, and the new WideArithmeticTests expectations are what the old code gave there.
  • iBook G4 (PowerPC): there is no testing library in the SDK, so the new tests' expectations were run as a small program. All five failed or trapped with the old code and pass with the change.
  • The Utilities capture probe now runs to the end there, with 283 of 287 lines matching Mac OS 9.2.2, as on macOS.
  • The Picture.swift change has no test.

@colemancda
colemancda merged commit 7972743 into master Dec 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant